package com.miyake.client.datamanage;

import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.Panel;
import com.miyake.client.DataService;
import com.miyake.client.DataServiceAsync;

public class ShowTableSample {
	private DataServiceAsync service = DataService.Util.getInstance();
	public ShowTableSample(NodeProperty node, Panel panel) {
		final Grid grid = new Grid();
		panel.add(grid);
		grid.setBorderWidth(1);
		service.getTable(node.getKey(), new AsyncCallback<Table>() {
			@Override
			public void onFailure(Throwable caught) {
				Window.alert(caught.getMessage());
			}

			@Override
			public void onSuccess(Table result) {
				int row = 0;
				//grid.resizeRows(result.getTextData().size());
				for (String[] text : result.getTextData()) {
					grid.resizeColumns(text.length);
					grid.resizeRows(grid.getRowCount() + 1);
					for (int col = 0; col < text.length; col++) {
						grid.setText(row, col, text[col]);
					}
					row++;
					if (row > 3) {
						break;
					}
				}
			}
		});
	}

}
